import wx

class MyFrame(wx.Frame):
    def __init__(self, *args, **kw):
        super(MyFrame, self).__init__(*args, **kw)

        # 当前窗体的面板，绑定OnPaint事件
        self.Bind(wx.EVT_PAINT, self.on_paint)

    def on_paint(self, event):
        # 创建一个绘图上下文
        dc = wx.PaintDC(self)
        # 设置画笔和画刷
        dc.SetPen(wx.Pen(wx.BLACK, 4))
        # 设置画刷的颜色
        dc.SetBrush(wx.Brush(wx.RED))
        # 画一个矩形
        dc.DrawRectangle(50, 50, 200, 100)
        # 画一个字符串
        dc.DrawText("Hello, wxPython!", 60, 60)

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame(None, title="wxPython DC Example", size=(400, 300))
    frame.Show()
    app.MainLoop()
